package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.PraiseModifyService;
import com.qf.lanzhou.blog.api.service.impl.PraiseModifyServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author jian   取消点赞
 * @Date 2020/12/17 15:19
 * @JDK 1.8
 * @Version 1.0
 */
@WebServlet("/update.do")
public class PraiseModifyServlet extends BaseServletPost{
    private PraiseModifyService praiseModifyService=new PraiseModifyServiceimpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决请求的乱码
        req.setCharacterEncoding("utf-8");
        //解决响应乱码
        resp.setContentType("text/html;charset=utf-8");

        //获取参数(需要根据用户id  文章id和状态值,判断删除那条点赞信息)
        User user1 = (User) req.getSession().getAttribute("user");
        Long id = user1.getId();
        //转为string类型
        String userId = id + "";
        String articleId = req.getParameter("articleId");
        String praiseStatus = req.getParameter("priceStatus");

        //调用方法
        int i=praiseModifyService.delete(userId,articleId);
        System.out.println(i);
        if(i>=1){
            System.out.println("取消点赞");
            successResultWrite("取消点赞成功",resp);
        }
    }
}
